library(tidyverse)
library(plotly)
load("afp.RData")
pal1 <- read.table('./Source data/pal1.txt')[, 1]
name<-"PBMC"
expr.ft <- expr.ft %>%
  filter(disease == name)
meta <- group_by(expr.ft, celltype)
meta <- summarise(meta, Freq = length(cell) / nrow(meta))
write_csv(meta, str_c("PBMC",".csv"))
p <- ggplot(data = meta, aes(celltype, weight = Freq, fill = celltype)) +
  geom_hline(yintercept = seq(0.025, 0.125, 0.025), color = 'gray') +
  geom_bar(width = 0.7, size = 0.8, color = 'black') +
  scale_fill_manual(values = pal1) +
  scale_y_continuous(expand = c(0, 0)) +
  theme_classic() +
  labs(y = 'Percentage of cells') +
  theme(axis.title.x = element_blank(), axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1),
        axis.line = element_line(size = 0.7), axis.ticks = element_line(size = 0.7), legend.position = 'none')
ggsave(filename = 'cellfreq.pdf', plot = p, width = 8, height = 6)
# gp<-ggplotly(p)
# htmlwidgets::saveWidget(as_widget(gp), "index.html")
